home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************
- *
- * Generic Appshell- a system 7.0 compatible application shell
- *
- * ©1992 Graham Cox. All Rights Reserved.
- *
- * This file contains code which may require modification to incorporate your
- * application's functionality. This works closely with Generic_Main to implement
- * the basic application shell. Always place these two files in the same segment.
- *
- * Modification History:
- * 10/2/92 created from scratch.
- *
- *
- *
- *************************************************************************************/
-
- #include "PDPGlobalEqu.p"
- #include "AppleEvents.h"
-
- #include "PDPVectors.proto.h"
-
- extern MenuHandle AppMenus[NumMenus]; /* Handles to the menus */
- extern short done;
- extern int AssemblyDest;
-
- GrafPtr StatBarGrafix; /* offscreen port with buttons in it */
-
- GrafPtr MakeAPort(int pictID,int pixDepth);
- ControlHandle GetMemScrollbar(WindowPtr theWindow);
- char IsEditKind(WindowPtr theWindow);
-
-
- AppInitialize(void)
- {
- /* application initialisation. Use this routine to create menu list, windows, etc */
-
- int index;
- MenuHandle temp;
-
- for (index = appleMenu;index < NumMenus;index++) {
- temp = GetMenu(standardResID+index);
- if (temp != NIL) {
- AppMenus[index] = temp;
- InsertMenu(AppMenus[index],0);
- }
- }
- if (AppMenus[appleMenu] != NIL)
- AddResMenu(AppMenus[appleMenu],'DRVR');
-
- CheckItem(AppMenus[asmMenu],ItemToDisk+AssemblyDest,TRUE);
- DrawMenuBar();
-
- StatBarGrafix = MakeAPort(130,0);
-
- }
-
-
- DispatchMenu(long mSelect)
- {
- /* called for menu selection to dispatch commands. Menu ID must be same as original
- resource ID */
-
- int theMenu,theItem,DARef;
- Str255 DAName;
- GrafPtr savePort;
- MenuHandle mH;
-
- theMenu = HiWord(mSelect);
- theItem = LoWord(mSelect);
-
- switch (theMenu-standardResID) {
- case appleMenu:
- if (theItem == ItemAbout) {
- SetDAFont(geneva);
- DoAbout();
- SetDAFont(0);
- }
- else {
- GetItem(AppMenus[appleMenu],theItem,&DAName);
- GetPort(&savePort);
- DARef = OpenDeskAcc(&DAName);
- SetPort(savePort);
- }
- break;
- case fileMenu:
- FileMenu(theItem);
- break;
- case editMenu:
- EditMenu(theItem);
- break;
- case pdpMenu:
- PDPMenu(theItem);
- break;
- case asmMenu:
- mH = GetMHandle(theMenu);
- AssembleMenu(mH,theItem);
- default:
- break;
- }
- }
-
-
- DoAbout(void)
- {
- /* puts up about dialog box */
-
- int aboutHit;
-
- aboutHit = xAlert(standardResID,NIL);
- }
-
-
- ClickTheWindow(WindowPtr theWindow,Point clickPt)
- {
- /* called when window clicked in content region. clickPt is in global coordinates */
-
- GrafPtr savePort;
-
- if (theWindow != NIL) {
- if (theWindow != FrontWindow())
- SelectWindow(theWindow);
- else {
- GetPort(&savePort);
- SetPort(theWindow);
- GlobalToLocal(&clickPt);
-
- if (IsSimulator(theWindow))
- ClickSimWindow(theWindow,clickPt);
- else
- if (IsEditKind(theWindow))
- ClickEditWindow(theWindow,clickPt);
- SetPort(savePort);
- }
- }
- }
-
-
- DragTheWindow(WindowPtr theWindow,Point dragPt)
- {
- /* drags the window. dragPt is in global coordinates */
-
- Rect dragBounds;
- RgnHandle deskTopRgn;
-
- if (theWindow != NIL) {
- deskTopRgn = GetGrayRgn();
- if (deskTopRgn != NIL)
- dragBounds = (*deskTopRgn)->rgnBBox;
- else {
- dragBounds = screenBits.bounds;
- dragBounds.top += MBarHeight;
- }
-
- InsetRect(&dragBounds,4,4);
-
- DragWindow(theWindow,dragPt,&dragBounds);
- }
- }
-
-
- GrowTheWindow(WindowPtr theWindow,Point growPt)
- {
- /* resizes the window. growPt is in global coordinates */
-
- Rect sizeRect,sbRect;
- RgnHandle sBarRgn,wpRgn;
- long growSize;
- GrafPtr savePort;
-
- if (theWindow != NIL) {
- GetPort(&savePort);
- SetPort(theWindow);
- sizeRect = screenBits.bounds;
- sizeRect.top = 100; /* min vertical size */
- sizeRect.left = 200; /* min horizontal size */
-
- growSize = GrowWindow(theWindow,growPt,&sizeRect);
-
- if (growSize != 0) {
- if (IsSimulator(theWindow))
- ResizeWindow(theWindow,LoWord(growSize),HiWord(growSize));
- if (IsEditKind(theWindow))
- ResizeEdWindow(theWindow,LoWord(growSize),HiWord(growSize));
- }
-
- SetPort(savePort);
- }
- }
-
-
- CloseTheWindow(WindowPtr theWindow)
- {
- if (IsSimulator(theWindow))
- DisposeProcessWindow(theWindow);
- if (IsEditKind(theWindow))
- DisposeEditWindow(theWindow);
- }
-
-
- ZoomTheWindow(WindowPtr theWindow,int partCode)
- {
- /* zooms window- you may need to do more for scrollbars, etc */
-
- GrafPtr savePort;
-
- if (theWindow != NIL) {
- GetPort(&savePort);
- SetPort(theWindow);
- EraseRect(&theWindow->portRect);
- if (IsSimulator(theWindow))
- ZoomScrollWindow(theWindow,partCode,TRUE);
- if (IsEditKind(theWindow))
- ZoomEdScrollWindow(theWindow,partCode,TRUE);
- InvalRect(&theWindow->portRect);
- SetPort(savePort);
- }
- }
-
-
- DrawTheWindow(WindowPtr theWindow)
- {
- /* draws the window's contents. Window is current port with correct visRgn, etc.
- This is entirely application dependent! */
-
- if (IsSimulator(theWindow))
- DrawPDPWindow(theWindow);
- if (IsEditKind(theWindow))
- DrawEditWindow(theWindow);
- DrawControls(theWindow);
- DrawGrowIcon(theWindow);
- }
-
-
- ActivateTheWindow(WindowPtr theWindow)
- {
- /* called when theWindow becomes active */
- ControlHandle mBar,hBar;
-
- if (theWindow != NIL) {
- SetPort(theWindow);
- DrawGrowIcon(theWindow);
- if (IsSimulator(theWindow))
- mBar = GetMemScrollbar(theWindow);
- else
- if (IsEditKind(theWindow)) {
- GetScrollBars(theWindow,&mBar,&hBar);
- if (hBar != NIL)
- HiliteControl(hBar,0);
- }
- if (mBar != NIL)
- HiliteControl(mBar,0);
- }
- }
-
-
- DeactivateTheWindow(WindowPtr theWindow)
- {
- /* called when theWindow is deactivated */
- ControlHandle mBar,hBar;
-
- DrawGrowIcon(theWindow);
- if (IsSimulator(theWindow))
- mBar = GetMemScrollbar(theWindow);
- else
- if (IsEditKind(theWindow)) {
- GetScrollBars(theWindow,&mBar,&hBar);
- if (hBar != NIL)
- HiliteControl(hBar,255);
- }
- if (mBar != NIL)
- HiliteControl(mBar,255);
- }
-
-
- ResumeApplication(void)
- {
- /* called when application resumed under multifinder */
-
- }
-
-
- SuspendApplication(void)
- {
- /* called when application suspended under multifinder */
-
- }
-
-
- pascal OSErr OpenApplication(AppleEvent *theAEvt,AppleEvent *reply,long hRefCon)
- {
- /* required apple event handler for open application- normally calls New */
- OpenNewWindow();
- return(noErr);
- }
-
-
- pascal OSErr OpenDocuments(AppleEvent *theAEvt,AppleEvent *reply,long hRefCon)
- {
- /* required apple event handler for open docs- normally calls Open */
- return(noErr);
- }
-
-
- pascal OSErr PrintDocuments(AppleEvent *theAEvt,AppleEvent *reply,long hRefCon)
- {
- /* required apple event handler for printing docs- normally calls Print */
- return(noErr);
-
- }
-
-
- pascal OSErr QuitApplication(AppleEvent *theAEvt,AppleEvent *reply,long hRefCon)
- {
- /* required apple event handler for quit application */
- return(noErr);
-
- }
-